﻿using System;
using System.Web.UI;
using AjaxControlToolkit;
using BluePortal.Medias.Core;

namespace BluePortal.QuikStart.UserControls
{
    public partial class MediaRating : System.Web.UI.UserControl
    {
        BCMedia bc = new BCMedia();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["vid"] != null)
            {
                Guid videoId = new Guid(Request.QueryString["vid"]);
                Media m = bc.FindByID(videoId);
                if (m.Rating != null)
                    RatingVideo.CurrentRating = m.Rating.Value;
                else
                    RatingVideo.CurrentRating = 0;
                PersonalRatingVideo.Tag = videoId.ToString();
                PersonalRatingVideo.CurrentRating = bc.FindUserRating(videoId, Page.User.Identity.Name);
            }
        }

        protected void RatingVideo_Changed(object sender, RatingEventArgs e)
        {
            bc.AddRating(new Guid(e.Tag), Page.User.Identity.Name, Int32.Parse(e.Value));
        }
    }
}